#define UNICODE

#include "CView.hpp"
#include "CMainView.hpp"
#include "CLeftView.hpp"
#include "CRightView.hpp"
#include "CSetDialog.hpp"
#include "CGridLayout.hpp"
#include "CMainFrame.hpp"
#include "CWindowBase.hpp"

LRESULT OnStartCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid);
LRESULT OnStopCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid);
LRESULT OnTDSetCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid);
LRESULT OnXTSetCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid);
LRESULT OnHelpCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid);

HWND hTDSetDlg;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    CMainFrame winapp(TEXT("MainClass"), hInstance);
    // 窗口宽度只包括客户区 窗口高度包括菜单栏,工具栏,客户区
    winapp.Create(1024, 768, TEXT("申港公安认证"));
    winapp.SetCallBack(IDB_BUTTON_START, OnStartCallback);
    winapp.SetCallBack(IDB_BUTTON_STOP, OnStopCallback);
    winapp.SetCallBack(IDB_BUTTON_TDSET, OnTDSetCallback);
    winapp.SetCallBack(IDB_BUTTON_XTSET, OnXTSetCallback);
    winapp.SetCallBack(IDB_BUTTON_HELP, OnHelpCallback);

    // RECT rect = {10, 30, 200, 200};
    // CWindowBase childWnd(TEXT("ChildClass1"), hInstance);
    // childWnd.Create(winapp.GetHWND(), &rect, TEXT("Child Window1"));
    // rect = {220, 30, 420, 200};
    // CWindowBase childWnd2(TEXT("ChildClass2"), hInstance);
    // childWnd2.Create(winapp.GetHWND(), &rect, TEXT("Child Window2"));

    CSetDialog setDialog(TEXT("SetDialog1"), hInstance);
    setDialog.Create(winapp.GetHWND(), NULL, TEXT("ChildWindow1"));
    hTDSetDlg = setDialog.GetHWND();

    // CSplitter childWnd(TEXT("splitter"), hInstance);
    // childWnd.SetMenuBarRect(winapp.GetMenuBarRect());
    // childWnd.SetToolBarRect(winapp.GetToolBarRect());
    // childWnd.Create(winapp.GetHWND(), NULL, TEXT("Child Window1"));

    // CView *view = new CView(TEXT("View1"), hInstance);
    // view->SetMenuBarRect(winapp.GetMenuBarRect());
    // view->SetToolBarRect(winapp.GetToolBarRect());
    // view->Create(winapp.GetHWND(), NULL, TEXT("Child Window1"));

    // CMainView mainView(TEXT("MainView1"), hInstance);
    // mainView.SetMenuBarRect(winapp.GetMenuBarRect());
    // mainView.SetToolBarRect(winapp.GetToolBarRect());
    // mainView.Create(winapp.GetHWND(), NULL, TEXT(""));

    // CLeftView leftView(TEXT("LeftView1"), hInstance);
    // leftView.Create(mainView.GetLefthWnd(), NULL, TEXT(""));

    // CRightView rightView(TEXT("RightView1"), hInstance);
    // rightView.Create(mainView.GetRighthWnd(), NULL, TEXT(""));

    CGridLayout gridLayout(TEXT("gridLayout1"), hInstance);
    gridLayout.SetMenuBarRect(winapp.GetMenuBarRect());
    gridLayout.SetToolBarRect(winapp.GetToolBarRect());
    gridLayout.Create(winapp.GetHWND(), NULL, TEXT("ChildWindow1"));
    gridLayout.SetGridSpacing(2, 6);

    ShowWindow(winapp.GetHWND(), SW_SHOWNORMAL);
    UpdateWindow(winapp.GetHWND());
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

LRESULT OnStartCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid)
{
    SetWindowText(hWnd, TEXT("OnStartCallback"));
    return 0;
}

LRESULT OnStopCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid)
{
    SetWindowText(hWnd, TEXT("OnStopCallback"));
    return 0;
}

LRESULT OnTDSetCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid)
{
    RECT rcParent;
    GetWindowRect(hWnd, &rcParent);
    MoveWindow(hTDSetDlg, rcParent.left + 50, rcParent.top + 50, (rcParent.right - rcParent.left) - (50 * 2), (rcParent.bottom - rcParent.top) - (50 * 2), TRUE);
    ShowWindow(hTDSetDlg, SW_SHOW);
    SetWindowText(hWnd, TEXT("OnTDSetCallback"));
    return 0;
}

LRESULT OnXTSetCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid)
{
    SetWindowText(hWnd, TEXT("OnXTSetCallback"));
    return 0;
}

LRESULT OnHelpCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LPVOID lpVoid)
{
    SetWindowText(hWnd, TEXT("OnHelpCallback"));
    return 0;
}